package bishi.day19_5_16;

import java.util.Scanner;

/**
 * 查找a,b两个公共最长字符串
 *
 * @author 是阿秋啊
 * @date 2022/05/16 21:43
 **/
public class find_maxlen_string {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String a = sc.nextLine();
            String b = sc.nextLine();
            if (a.length() > b.length()) {
                String tmp = b;
                b = a;
                a = tmp;
            }
            int la = a.length();
            int lb = b.length();
            int begin = 0;
            int maxLen = 0;
            for (int i = 0; i < la; i++) {
                for (int j = 0; j < lb; j++) {
                    if (a.charAt(i) == b.charAt(j)) {
                        int tempLen = helper(a.substring(i), b.substring(j));
                        if (maxLen < tempLen) {
                            begin = i;
                            maxLen = tempLen;
                        }
                    }
                }
            }
            System.out.println(a.substring(begin, begin + maxLen));
        }
    }

    private static int helper(String a, String b) {
        int ret = 0;
        int la = a.length();
        int lb = b.length();
        int i = 0;
        while (i < la && i < lb && a.charAt(i) == b.charAt(i)) {
            i++;
            ret++;
        }
        return ret;
    }
}